import { defineStore } from 'pinia'

const userStoreCreater = defineStore({
  id: 'userState',

  state: () => ({
    token: null,
    user: null, // 用户信息
  }),
  getters: {
    getToken() {
      return this.token
    },
  },
  actions: {},
  // 持久化
  persist: {
    enabled: true, // 开启数据缓存
    strategies: [
      {
        key: 'user_state',
        storage: localStorage,
        paths: ['token', 'user'],
      },
    ],
  },
})

export default userStoreCreater
